define([
  'vue',
  'text!' +
  ELMP.resource('components/base-info/index.html', 'tmzk_workflow'),
  ELMP.resource('components/vue-collapse/index.js', 'lib'),
], function (Vue, template, vueCollapse) {
  return {
    components: {
      vueCollapse,
    },
    template,
    props: {
      header: { type: String, default: '' },
      isStart: { type: Boolean, default: false }
    },
    data () {
      return {
        isDisabled: false,
        form: {
          name: '',
          description: '',
          dueDate: $.Utils.getDate(7),
          priority: '50',
        },
        rules: {},
        levelOption: [],
      }
    },
    created () {
      this.rules = $.Utils.initFormReq(this.form, ["dueDate", "priority"])
    },
    mounted () {
      const that = this
      this.levelOption = $.dict.values('workflow_priority')
      // if (this.isStart) {
      //   this.form.dueDate =
      //   this.form.priority = "50"
      // }
      this.$nextTick(() => {
        that.$refs.form.clearValidate()
      })
    },
    methods: {
      // 是否必填
      requireFun (arr) {
        this.rules = $.Utils.initFormReq(this.form, arr)
      },
      getFormData (isDraft) {
        const that = this
        return new Promise((r, j) => {
          if (isDraft) { r(that.form) } else {
            this.$refs.form.validate((access) => {
              if (access) {
                r(that.form)
              } else {
                $.msg.tips('基本信息必填项不能为空!')
                j()
              }
            })
          }

        })
      },
      setFormData (data, disabled = false) {
        this.form = Object.assign(this.form, data)
        this.isDisabled = disabled
      },
    },
  }
})
